package com.astersoft.lib.util.singleton;

import java.lang.reflect.ParameterizedType;

public abstract class ASSingleton<T> {
	private static Object instance = null;
	
	@SuppressWarnings("unchecked")
	public static <T> T getInstance(Class<T> cl) {
		if (instance == null) {
			try {
				instance = ((Class<T>)((ParameterizedType) cl.getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
			} catch(Exception e) {
				e.printStackTrace();
			}
		}
		return (T)instance;
	}
}
